package logic

import (
	"context"
	"video-hubs/model/mysql"

	"video-hubs/videorpc/internal/svc"
	"video-hubs/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SangAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSangAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SangAddLogic {
	return &SangAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SangAddLogic) SangAdd(in *videorpc.SangAddRequest) (*videorpc.SangAddResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.Sang

	if err := user.FindSang(mysql.DB, in.Name); err == nil {
		return nil, err
	}
	data := &mysql.Sang{
		Name:   in.Name,
		Type:   in.Type,
		Price:  in.Price,
		UserId: int(in.UserId),
	}
	if err := data.AddSang(mysql.DB); err != nil {
		return nil, err
	}
	return &videorpc.SangAddResponse{
		SangId: int64(data.ID),
	}, nil
}
